from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Line
from pyecharts.faker import Faker

bar = (
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis("商家A", Faker.values())
    .add_yaxis("商家B", Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Grid-Bar"),
        # legend_opts=opts.LegendOpts(pos_top="10%"),
    )
)
line = (
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis("商家A", Faker.values())
    .add_yaxis("商家B", Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"),
        # legend_opts=opts.LegendOpts(pos_top="10%"),
    )
)

grid = (
    Grid(init_opts=opts.InitOpts(width="1600px", height="800px"))
    # pos_bottom    grid 组件离容器底部的距离
    # pos_top       grid 组件离容器顶部的距离
    # .add(bar, grid_opts=opts.GridOpts(pos_bottom="60%"))
    # .add(line, grid_opts=opts.GridOpts(pos_top="60%"))
    #     .render("grid_vertical.html")
    # pos_left      grid 组件离容器左侧的距离
    # pos_right     grid 组件离容器右侧的距离
    .add(bar, grid_opts=opts.GridOpts(pos_left="53%"))
    .add(line, grid_opts=opts.GridOpts(pos_right="53%"))
    .render("grid_horizontal.html")
)
